package com.stockz.equity.charting.view;

import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.event.listener.ScrollListener;
import com.stockz.equity.charting.event.listener.SelectionListener;

@Component
@Scope("prototype")
public class StockChart extends JScrollPane{
	private static final long serialVersionUID = 3481326907257208725L;
	
	private final StockChartPanel stockChartPanel;
	
	@Autowired private SelectionListener selectionListener;
	@Autowired private ScrollListener scrollListener;
	
	@Autowired
	public StockChart(StockChartPanel stockChartPanel,
			StockChartViewSkin stockChartViewSkin,
			StockChartViewStructure stockChartViewStructure){
		super(stockChartPanel);
		this.stockChartPanel = stockChartPanel; 
		this.stockChartPanel.setStockChart(this);

		getHorizontalScrollBar().addMouseListener(scrollListener);
		getHorizontalScrollBar().addMouseListener(selectionListener);
		getHorizontalScrollBar().addMouseMotionListener(scrollListener);
		getHorizontalScrollBar().addMouseMotionListener(selectionListener);
		
		getVerticalScrollBar().addMouseListener(scrollListener);
		getVerticalScrollBar().addMouseListener(selectionListener);
		getVerticalScrollBar().addMouseMotionListener(scrollListener);
		getVerticalScrollBar().addMouseMotionListener(selectionListener);
		
		addMouseListener(selectionListener);
		addMouseMotionListener(selectionListener);
		
		setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		setBorder(null);
	}
	
	public StockChartPanel getStockChartPanel() {
		return stockChartPanel;
	}
}